//createRouter创建路由实例
//createWebHistory创建history路由
import { createRouter, createWebHistory } from 'vue-router'
import Login from '../views/Login/index.vue'
import Layout from '../views/Layout/index.vue'
import Home from '../views/Home/index.vue'
import Category from '../views/Category/index.vue'
import sammllcate from '../views/samllcate/index.vue'
import detail from '../views/detail/index.vue'
import Cartlist from '../views/Cartlist/index.vue'
import Money from '../views/money/index.vue'
import Pay from '../views/Pay/index.vue'
import User from '../views/user/index.vue'
import Info from '../views/user/components/info.vue'
import Order from '../views/user/components/order.vue'
const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes: [
    {
      path: '/', component: Layout,
      //当path路径为空时 展示 /路由的页面时 ''空路由的页面也会展示
      //当展示 /路由时 Home也会展示
      children: [{ path: '', component: Home },
      { path: '/category/:id', component: Category },
      { path: '/category/sub/:id', component: sammllcate },
      { path: 'detail/:id', component: detail },
      { path: '/cartlist', component: Cartlist },
      { path: '/checkout', component: Money },
      { path: '/pay', component: Pay },
      { path: '/member', component: User,redirect:'/member/user',
        children:[
          {path:'/member/user',component:Info},
          {path:'/member/order',component:Order}
        ],
      },
      ]
    },
    { path: '/login', component: Login },

  ],
  //切换路由时将界面显示为最上方
  scrollBehavior() {
    return { top: 0 }
  }
})

export default router
